home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2005 May / PC för Alla 0505.iso / fullversioner / realsoft3d / data1.cab / Scripting / scripts / js / myclasses / windows / mySpherePropWin.js < prev   
Encoding:
Text File  |  2005-04-04  |  3.4 KB  |  122 lines

  1.  
  2. //
  3. // Description:
  4. //      Model-view example class. Defines a simple property window which allows
  5. //      the user to modify the center attribute of the selected sphere objects.
  6. //
  7. // Super class:
  8. //      oops/r3window.js
  9. //
  10. // Constructor:
  11. //      obj = new mySpherePropWin(tag list);
  12. //
  13. //
  14.  
  15. include("oops/r3window.js");
  16. include("oops/r3packer.js");
  17. include("real/objects/r3sphere.js");
  18. include("real/gadget/r3vectg.js");
  19.  
  20. // callback method which will be called by our model object
  21. // whenever the status of the model is changed
  22.  
  23. function myUPDATE(value, id, event)
  24. {
  25.     if(event == 0 ||
  26.        event == R3OLAYM_SELECTOBJ ||
  27.        event == R3PRIMM_TRANSFORM ||
  28.        event == R3SPHA_Center) {
  29.         if(this.model) {
  30.             this.model.LOCKSHARED(0);
  31.             obj = this.model.GETFIRSTSELECTED();
  32.             this.model.RELEASE(0);
  33.             if(obj) {
  34.                 if(obj.ISOFKIND(R3CLID_SPHERE)) {
  35.                     center = obj.GetCenter();
  36.                     if(center) {
  37.                         this.center.SetConflict(FALSE);
  38.                         this.center.SetValue(center);
  39.                     }
  40.                     else
  41.                         this.center.SetConflict(FALSE);
  42.                 }
  43.                 else 
  44.                     this.center.SetConflict(TRUE);
  45.             }
  46.             else {
  47.                 this.center.SetConflict(TRUE);
  48.             }
  49.         }
  50.         else this.center.SetConflict(TRUE);        
  51.     }
  52. }
  53.  
  54. // catch the close window event and detach the model
  55.  
  56. function mySpherePropWinHook(obj, method, val)
  57. {
  58.     if(method == R3WM_CLOSEWINDOW) {
  59.         obj.SetModel(0);
  60.         obj.center.SetUnitConverter(0);
  61.         return 1;   // yes, close
  62.     }
  63.     return 1;
  64. }
  65.  
  66. // callback for the center field, this allows the user to
  67. // modify the center
  68.  
  69. function mySphereSetCenterHook(obj, event, value)
  70. {
  71.     this.model.SETONSELECTED([R3SPHA_Center, value]);
  72. }
  73.  
  74. // a method which allows the user to set our model
  75.  
  76. function mySetModel(model)
  77. {
  78.     if(this.model) // detach from current
  79.         this.model.REMOVEDEPENDENT(this);
  80.     this.model = model;
  81.     if(this.model) // attach to new
  82.         this.model.ADDDEPENDENT(0, 0, this);
  83.     mySphereSetCenterHook.model = model; // tell the hook were to find the model
  84.     this.UPDATE(0, 0, 0);   // full update
  85. }
  86.  
  87. // constructor 
  88.  
  89. function mySpherePropWin()
  90. {
  91.     // call super class 
  92.     if(arguments.length == 0)
  93.         return;
  94.  
  95.     this.model = 0;
  96.     this.base = r3Window;
  97.     this.base(R3WA_ReportNewSize, TRUE,
  98.               R3WA_ReportCloseWindow, TRUE,
  99.               R3WA_Title, "Sphere Property Window",
  100.               R3RA_Hook, mySpherePropWinHook,
  101.               arguments);
  102.  
  103.     // define methods 
  104.     this.UPDATE = myUPDATE;
  105.     this.SetModel = mySetModel;
  106.     
  107.     // define user interface
  108.     this.packer = new r3Packer(R3PA_Orientation, R3PAOF_VERTICAL);
  109.  
  110.     this.center = new r3Vectorgadget(R3WGA_Parent, this,
  111.                                     R3GA_Text, "Center",
  112.                                      R3RA_Hook, mySphereSetCenterHook);
  113.     
  114.     // set unitconverter, vector gaget needs it
  115.     this.center.SetUnitConverter(GetJS("CurrentProject.UnitConverter"));
  116.  
  117.     this.packer.ADD(R3PAPF_FILLX, 0, this.center);
  118.     this.SetGmanager(this.packer);
  119. }
  120.  
  121. mySpherePropWin.prototype=new r3Window;
  122.